﻿using System;
using System.Runtime.Remoting.Messaging;
using GrayParrot.Configuration;
using GrayParrot.Configuration.Logging;
using log4net;
using GrayParrot.Infrastructure;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UTLogging
{
    [TestClass]
    public class UnitTest1
    {
        /// <summary>
        /// Tests Log4Net con file di configurazione...
        /// </summary>
        [TestMethod]
        public void TestLogging1()
        {
            GrayParrot.Logging.Logger.For<UnitTest1>().Debug("Test GrayParrot.Logging.Logger4 Logging");
        }

        /// <summary>
        /// Tests Log4Net SENZA file di configurazione, ma con inizializzazione via codice degli appender ( Console, DB, File RollingAppender )
        /// </summary>
        [TestMethod]
        public void TestLogging2()
        {
            LogSettings logConfig = ConfigurationManagerHelper.Get<LogSettings>("grayParrotGroup/logSettings");
            string cn = logConfig.Database.ConnectionString;
            string tbn = logConfig.Database.TableName;

            GrayParrot.Logging.Logger.ConfigureWithDb(cn, tbn, false);
            //GrayParrot.Logging.Logger<UnitTest1>.ConfigureWithDb(@"Data Source=172.16.200.73;Initial Catalog=Radamanto;User ID=logging;Password=controllosessioni", "LogComplementare", false);
            //GrayParrot.Logging.Logger<UnitTest1>.ConfigureWithFile(@"c:\logs\GrayParrot.txt");

            GrayParrot.Logging.Logger.For<UnitTest1>().Debug("Test ConfigureWithDb3336 Logging");
        }

        [TestCleanup]
        public void Cleanup()
        {
            CallContext.FreeNamedDataSlot("log4net.Util.LogicalThreadContextProperties");
        }

        [WithExceptionHandling]
        [TestMethod]
        public void TestWithParameters(int uno, string due)
        {
            int a = 0;
            int b = 1;

            int c = 0;

            c = a / b;
        }
    }
}
